/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-11-13 下午8:59 Created by dwzhang
 */
package com.jade.modules.protocol;

import java.util.Map;

/**
 * 抽象的协议工厂。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-11-13 下午8:59
 */
public abstract class AbstractProtocolFactory
        implements ProtocolFactory
{
    private Map<String, String> protocolMap;

    public void setProtocolMap(Map<String, String> protocolMap)
    {
        this.protocolMap = protocolMap;
    }

    public <T> T createProtocolClient(ProtocolChannel channel)
    {
        //获取客户端类信息。
        String protocol = channel.getProtocol();
        String clazz = protocolMap.get(protocol);
        return clazz == null ? null : (T) createProtocolClient(clazz, channel);
    }

    public abstract <T> T createProtocolClient(String clazz, ProtocolChannel channel);
}
